<cfparam default="" name="PageType" />

<cfoutput>	  
    
    <!---BillableServices is set in showreport--->    
    
    <cfif PageType EQ "PDF">
    
    	<!---HTML header, css links, js links, and page title--->
    	#BASE.htmlHeader("", "", "Elder's Program - Reports")#
   		<!---HTML header, css links, js links, and page title--->

		<cfdocument format="pdf">
       
       <cfset pageCount = 0 /> 
       
       <cfdocumentitem type= "footer">
			#cfdocument.currentpagenumber# of #cfdocument.totalpagecount#
       </cfdocumentitem>
       
    	<h2>Billable #url.BillingType#</h2>
    
        <table>
            <thead>
                <tr>
                    <th colspan="3">From #url.DateFrom# to #url.DateTo#</th>
                </tr>
                <tr>
                    <th>Elder Name</th>
                    <th>Service</th>
                    <th>Total Units</th>
                    <th>Unbilled Units</th>
                </tr>
            </thead>
            <tbody>
            
                <cfif url.BillingType EQ "Services">
                
                    <cfloop query="BillableServices">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Chore">
                    
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Meals">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Transportation">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "TTCM">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelse>
                    
                    <cfloop query="BillableServices">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                    
                </cfif>
            
            
            </tbody>
        </table>
        
        </cfdocument>
        
        <!---HTML footer, closes html and body tags.  Any footer info goes here--->
        #BASE.htmlFooter()#
        <!---HTML footer, closes html and body tags.  Any footer info goes here--->
        
    <cfelseif PageType EQ "XLS">
    	
        <!--- Set this HTTP Document as an Excel Spreadsheet --->
        <cfheader name="Content-Type:" value="application/vnd.ms-excel">
        <cfheader name="Content-Disposition:" value="attachment; filename=BillableServices_From_#url.DateFrom#_to_#url.DateTo#.xls">
        
        <!--- Output ONLY items enclosed in CF tags --->
		<cfsetting enablecfoutputonly="true">
        
        <table>
            <thead>
                <tr>
                    <th style="border:1px solid ##000">Elder Name</th>
                    <th style="border:1px solid ##000">Service</th>
                    <th style="border:1px solid ##000">Total Units</th>
                    <th style="border:1px solid ##000">Unbilled Units</th>
                </tr>
            </thead>
            <tbody>
            
                <cfif url.BillingType EQ "Services">
                
                    <cfloop query="BillableServices">
                    <tr>
                        <td style="border:1px solid ##000">#NAME#</td>
                        <td style="border:1px solid ##000">#SERVICE#</td>
                        <td style="border:1px solid ##000">#TOTALUNITS#</td>
                        <td style="border:1px solid ##000">#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Chore">
                    
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td style="border:1px solid ##000">#NAME#</td>
                        <td style="border:1px solid ##000">#SERVICE#</td>
                        <td style="border:1px solid ##000">#TOTALUNITS#</td>
                        <td style="border:1px solid ##000">#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Meals">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td style="border:1px solid ##000">#NAME#</td>
                        <td style="border:1px solid ##000">#SERVICE#</td>
                        <td style="border:1px solid ##000">#TOTALUNITS#</td>
                        <td style="border:1px solid ##000">#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Transportation">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td style="border:1px solid ##000">#NAME#</td>
                        <td style="border:1px solid ##000">#SERVICE#</td>
                        <td style="border:1px solid ##000">#TOTALUNITS#</td>
                        <td style="border:1px solid ##000">#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "TTCM">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td style="border:1px solid ##000">#NAME#</td>
                        <td style="border:1px solid ##000">#SERVICE#</td>
                        <td style="border:1px solid ##000">#TOTALUNITS#</td>
                        <td style="border:1px solid ##000">#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelse>
                    
                    <cfloop query="BillableServices">
                    <tr>
                        <td style="border:1px solid ##000">#NAME#</td>
                        <td style="border:1px solid ##000">#SERVICE#</td>
                        <td style="border:1px solid ##000">#TOTALUNITS#</td>
                        <td style="border:1px solid ##000">#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                    
                </cfif>
            
            
            </tbody>
        </table>
    
    <cfelse>
    
    	 <!---HTML header, css links, js links, and page title--->
    	#BASE.htmlHeader("", "", "Elder's Program - Reports")#
   		<!---HTML header, css links, js links, and page title--->

    	<h2>Billable #url.BillingType#</h2>
    
    	<table>
            <thead>
                <tr>
                    <th colspan="3">From #url.DateFrom# to #url.DateTo#</th>
                </tr>
                <tr>
                    <th>Elder Name</th>
                    <th>Service</th>
                    <th>Total Units</th>
                    <th>Unbilled Units</th>
                </tr>
            </thead>
            <tbody>
            
                <cfif url.BillingType EQ "Services">
                
                    <cfloop query="BillableServices">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Chore">
                    
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Meals">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "Transportation">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelseif url.BillingType EQ "TTCM">
                
                    <cfquery dbtype="query" name="BillableType">
                        SELECT *
                        FROM BillableServices
                        WHERE Service = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BillingType#" />
                    </cfquery>
                    
                    <cfloop query="BillableType">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                
                <cfelse>
                    
                    <cfloop query="BillableServices">
                    <tr>
                        <td>#NAME#</td>
                        <td>#SERVICE#</td>
                        <td>#TOTALUNITS#</td>
                        <td>#UNBILLEDUNITS#</td>
                    </tr>
                    </cfloop>
                    
                </cfif>
            
            
            </tbody>
        </table>
        
        <!---HTML footer, closes html and body tags.  Any footer info goes here--->
        #BASE.htmlFooter()#
        <!---HTML footer, closes html and body tags.  Any footer info goes here--->

    
    </cfif>
        
</cfoutput>